//
//  JHJInfoViewController.m
//  DayByDay
//
//  Created by dllo on 16/5/20.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "JHJInfoViewController.h"
#import <AFNetworking.h>

@interface JHJInfoViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *array;
@property (nonatomic, assign)BOOL smallscrollEnable;
@property (nonatomic, copy)NSString *value;

@end

@implementation JHJInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.smallscrollEnable = NO;
    self.array = [NSMutableArray array];
    [self createData];
    [self createView];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeSmallScrollEnable:) name:@"firstScrollEnable" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeValue:) name:@"deliverValue1" object:nil];
}

- (void)changeSmallScrollEnable:(NSNotification *)noti {
    self.smallscrollEnable = ![[noti object] boolValue];
}

- (void)changeValue:(NSNotification *)noti {
    self.value = [noti object];
    
}

- (void)setValue:(NSString *)value {
    _value = value;
    if (self.array.count == 0) {
        [self createData];
    }
    
}


- (void)createData {
//    NSString *firstStr =
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
}

- (void)createView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT- 64) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//    if (indexPath.row == 0) {
//        return 200;
//    } else {
//        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
////        CGRect rect = [self.arr[indexPath.row] boundingRectWithSize:CGSizeMake(375, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
//        CGRect rect;
//        return rect.size.height;
//    }
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
    
    cell.backgroundColor = [UIColor redColor];
    
    return cell;
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.tableView) {
        NSLog(@"%f",self.tableView.contentOffset.y);
        if (!self.smallscrollEnable) {
            scrollView.contentOffset = CGPointZero;
            
        } else if (scrollView.contentOffset.y <= 0){
            self.smallscrollEnable = NO;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"bingScrollEnable" object:[NSNumber numberWithBool:self.smallscrollEnable]];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
